//
//  ShoppingCarXibTextViewController.swift
//  sss
//
//  Created by Mac on 2021/1/13.
//  Copyright © 2021 hrrMac. All rights reserved.
//

import UIKit



class ShoppingCarXibTextViewController: UIViewController {
    @IBOutlet weak var tableView: UITableView!

    @IBOutlet weak var shopCarBottomView: ShoppingCarBottomView!
    
    let identifierCell = "shopCell"
    let identifierHeader = "shopHeader"
    
    var dataArr: [ShopCarModel] = []
    
    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.delegate = self
        tableView.dataSource = self
        tableView.rowHeight = 115
        tableView.register(ShoppingCarTableViewCell.self, forCellReuseIdentifier: identifierCell)
        tableView.register(ShoppingCarHeaderView.self, forHeaderFooterViewReuseIdentifier: identifierHeader)
        
        shopCarBottomView.touchAllSelectEvent = { isAllSelect in
            
        }
    }

}


extension ShoppingCarXibTextViewController:UITableViewDelegate,UITableViewDataSource{
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return dataArr.count
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return dataArr[section].dataArr.count
    }
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 42
    }
    
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let header: ShoppingCarHeaderView = tableView.dequeueReusableHeaderFooterView(withIdentifier: identifierHeader) as! ShoppingCarHeaderView
        header.shopNameLab.text = "swift商店"
        let ShopCarModel = dataArr[section]
        header.touchSelectEvent = { [self] isSelect in
            ShopCarModel.isSelect = isSelect
        }
        return header
    }
    
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell: ShoppingCarTableViewCell = tableView.dequeueReusableCell(withIdentifier: identifierCell, for: indexPath) as! ShoppingCarTableViewCell
        cell.goodsNameLab.text = "购物车商品名称购物车商品名称购物车商品名称购物车商品名称购物车商品名称购物车商品名称"
        cell.goodsSpecificationLab.text = "规格：商品规格商品规格商品规格商品规格商品规格商品规格"
        cell.priceLab.text = "¥999999.00"
        cell.goodsImgView.backgroundColor = UIColor.gray
        cell.operationView.setParamert(indexPath.row)
        return cell
    }
    
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
    }
    
}
